/*
	This file is part of BGO External Jukebox.

	BGO External Jukebox is free software:
	you can redistribute it and/or modify it under the terms
	of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License,
	or (at your option) any later version.

	BGO External Jukebox is distributed  in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
	or FITNESS FOR A PARTICULAR PURPOSE.

	See the GNU General Public License for more details.

	You should have received a copy of the GNU General Public License  along with
	BGO External Jukebox. If not, see <http://www.gnu.org/licenses/>.
*/

var utils = {
	url: function() {
		if (this)
		{
			chrome.tabs.create({'url': this.href});
		}
	}
}

function defaultSetting(settingName, defaultValue)
{
	if (typeof(localStorage[settingName]) === 'undefined')
	{
		localStorage[settingName] = defaultValue;
	}
}

function setupInputSetting(settingName, settingInput)
{
	if (localStorage[settingName] == 1)
	{
		document.getElementById(settingInput).checked = true;
	}
	else
	{
		document.getElementById(settingInput).checked = false;
	}

	document.getElementById(settingInput).onclick = function()
	{
		localStorage[settingName] = (document.getElementById(settingInput).checked ? 1 : 0);
	}
}

defaultSetting('_bgo_detach_jukebox', 1);

document.addEventListener('DOMContentLoaded',
	function()
	{
		var urls = document.getElementsByClassName('_url');

		for (var i = 0; i < urls.length; ++i)
		{
			urls[i].onclick = utils.url;
		}

		setupInputSetting('_bgo_detach_jukebox', 'jukebox_type');
	}
);
